package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.*;
import com.atguigu.gmall.product.service.ManageService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/product")
//@CrossOrigin
public class BaseManageController {
    //调用服务层接口
    @Autowired
    private ManageService manageService;

    //获取一级分类数据
    @GetMapping("getCategory1")
    public Result getCategory1() {
        //调用服务层方法
        List<BaseCategory1> baseCategory1List = manageService.getCategory1();
        return Result.ok(baseCategory1List);
    }

    //获取二级分类数据
    @GetMapping("getCategory2/{category1Id}")
    public Result getCategory2(@PathVariable long category1Id) {
        //调用服务层方法
        List<BaseCategory2> baseCategory2List = manageService.getCategory2(category1Id);
        return Result.ok(baseCategory2List);
    }

    //获取三级分类数据
    @GetMapping("getCategory3/{category2Id}")
    public Result getCategory3(@PathVariable long category2Id) {
        //调用服务层方法
        List<BaseCategory3> baseCategory3List = manageService.getCategory3(category2Id);
        return Result.ok(baseCategory3List);
    }

    //根据分类Id 获取平台属性集合
    ///admin/product/attrInfoList/{category1Id}/{category2Id}/{category3Id}
    @GetMapping("attrInfoList/{category1Id}/{category2Id}/{category3Id}")
    public Result getattrInfoList(@PathVariable long category1Id,
                                  @PathVariable long category2Id,
                                  @PathVariable long category3Id) {
        //调用服务层方法
        //平台属性对象中 ，应该包含平台属性值集合！
       List<BaseAttrInfo> baseAttrInfoList = manageService.getattrInfoList(category1Id,category2Id,category3Id);
        return Result.ok(baseAttrInfoList);
    }
    //  /admin/product/saveAttrInfo
    @PostMapping("saveAttrInfo")
    public Result saveAttrInfo(@RequestBody BaseAttrInfo baseAttrInfo){
        //调用服务层方法
        manageService.saveAttrInfo( baseAttrInfo);
        //返回
        return Result.ok();
    }

    ///admin/product/getAttrValueList/{attrId}
    @GetMapping("getAttrValueList/{attrId}")
    public Result getAttrValueList(@PathVariable Long attrId){
        //调用服务层方法
        BaseAttrInfo baseAttrInfo = manageService.getBaseAttrInfo(attrId);
      return  Result.ok(baseAttrInfo.getAttrValueList());
    }
}
